package install.ren.exercise.test.kafka;

import lombok.Data;

/**
 * @author zhuyunhui
 * @Description: TODO
 * @date 2019-03-21 18:22
 */
@Data
public class ConsumerAssign {

    private Object lock = new Object();

    private volatile ConsumerRecords next;

    private String error;

    public void start(){
        synchronized (lock){

            lock.notifyAll();
        }
    }

    public ConsumerRecords assign() throws InterruptedException {

        synchronized (lock){
            System.out.println("assign=======");

            while (next == null && error == null){
                System.out.println("while-start" + Thread.currentThread().getName());
                lock.wait();
                System.out.println("while-end" + Thread.currentThread().getName());
            }

            ConsumerRecords<byte[],byte[]> n = next;
//            n.setName(Thread.currentThread().getName());
            if(n != null){
                next = null;
                lock.notifyAll();
                return  n;
            }else{
                return null;
            }
        }
    }


}
